﻿using System;
using System.Collections.Generic;
using System.Text;
using SpeechLib;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace UTIL
{
    public class CTextVoice
    {   
        #region 得到文本的数组 A-2009-05
        public static String[] GetDescriptionName()
        {
            SpVoice pv = new SpVoice();
            List<String> lstResult = new List<String>();
            ISpeechObjectTokens ist=null;
            ist = pv.GetVoices("", "");        
            foreach (SpObjectToken it in ist) 
           {
               lstResult.Add(it.GetDescription(0));
           }
           return lstResult.ToArray();
        }

        #endregion

        #region 试听朗读
        public static void SpeckPreListen(int itype, int indexPos, int iVolume, int iRate)
        {
            try
            {
                SpVoice tempVoice = new SpVoice();                
                {
                    SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFDefault;

                    String str = "这是一个测试";
                    if (itype == 0)
                    {
                        str = "This is a test";
                        tempVoice.Voice = tempVoice.GetVoices("", "").Item(indexPos);                       
                    }
                    else if (itype == 1)
                    {
                        str = "这是一个测试";
                        tempVoice.Voice = tempVoice.GetVoices("", "").Item(indexPos);                       
                    }
                    else if (itype == 2)
                    {
                        str = "私は王永勝";
                        tempVoice.Voice = tempVoice.GetVoices("", "").Item(indexPos);
                        
                    }
                    tempVoice.Volume = iVolume;
                    tempVoice.Rate = iRate;
                    tempVoice.Speak(str, SpFlags);
                }
                tempVoice = null;
            }
            catch (Exception me)
            {
                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
            }

        }
        #endregion

    }
}
